<?php
/**
* For Mobile connectors
* Get connected profile
* @author trungdt
* @since Dec 9, 2012
* 
* Input
* - session_id
* 
* Output
* {
*   status: OK | NOT_AUTHENTICATED | NOT_VALID 
*   profile fields
* }
* 
* - Client need to send their session_id to server to receive their profile
*/
    if (!defined('EXPONENT')) exit('');
    global $db;
    // include the mobile connectors
    include_once(BASE."modules/profilemodule/mobile_connector.php");
    
    $ret = null; // init object
    $ret->status = "NOT_VALID";
    
    if (isset($_POST['session_id']))
    {
        $session_id = _ab_safe_html_string($_POST['session_id']);
        
        profile_module_updateClientSession_last_response($session_id);
        // check session is still valid or not
        // all timedout session had been wiped
        $msession = $db->selectObject("profilemodule_mobilesession", "session_id = '{$session_id}'");
        
        if (isset($msession->id))
        {   
            // then get the profile
            $profile = $db->selectObject("profilemodule_profile", "user_id = {$msession->user_id}");
            $profile->status="OK";
            $ret=$profile;
            profile_module_updateClientSession_last_response();
        }
        else
        {
            $ret->status="NOT_AUTHENTICATED";
        }
    }
    
    echo json_encode($ret);
    die();
    
?>